using System;

namespace CavemanTools.Extensions
{
	public static class TimeUtils
	{
		/// <summary>
		/// Multiplies a time period by a number
		/// </summary>
		/// <param name="duration"></param>
		/// <param name="modifier"></param>
		/// <returns></returns>
		public static TimeSpan Multiply(this TimeSpan duration, float modifier)
		{
			if (modifier == 1) return duration;
			try
			{
				return TimeSpan.FromSeconds(duration.TotalSeconds*modifier);
			}
			catch(OverflowException ex)
			{
				if (ex.Message.Contains("long"))return TimeSpan.MaxValue;

				return TimeSpan.MinValue;
			}
		}
	}
}